package com.ljj.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.ljj.entity.Dto;
import com.ljj.entity.Student;
import com.ljj.mapper.StudentMapper;
import com.ljj.service.IStudentService;
import com.ljj.utli.Result;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liujiju
 * @since 2021-11-19
 */
@CrossOrigin
@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	IStudentService is;
	@Autowired
	StudentMapper m;

	/**
	 * 全查
	 * 
	 * @param d
	 * @return
	 */
	@RequestMapping("/getList")
	public Object getList(Dto d) {

		List<Student> list = is.getList(d);
		d.setLimit(null);
		d.setPage(null);
		List<Student> list1 = is.getList(d);
		return new Result(0, "", list, list1.size());
	}

	/**
	 * 添加
	 * 
	 * @param c
	 * @return
	 */
	@RequestMapping("/add")
	public Object add(Student c) {
		
		if (m.insert(c)> 0) {
			return new Result(0, "添加成功");
		} else {
			return new Result(1, "添加失败");
		}
	}

	/**
	 * 修改
	 * 
	 * @param d
	 * @return
	 */
	@RequestMapping("/update")
	public Object update(Student d) {
		if (m.updateById(d) > 0) {
			return new Result(0, "修改成功");
		} else {
			return new Result(1, "修改失败");
		}

	}

	/**
	 * 删除
	 * 
	 * @param d
	 * @return
	 */
	@RequestMapping("/detele")
	public Object detele(Student s) {
		
		if (m.deleteById(s)>0) {
			return new Result(0, "删除成功");
		} else {
			return new Result(1, "删除失败");
		}


	}

}
